////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2017-2018 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// THIS IS AUTO-GENERATED CODE.  PLEASE DO NOT EDIT (File bug reports against tools).
///
/// Auto-generated by: ParameterParser V1.1.4
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @file  camxpdafconfig.cpp
/// @brief Auto-generated Chromatix parameter file
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include "camxpdafconfig.h"
#include "parametersetmanager.h"

CAMX_NAMESPACE_BEGIN

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Default Constructor
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
PDAFConfigurationDataClass::PDAFConfigurationDataClass(
    const CHAR* name)
    : ParameterModule(name, MAJOR, MINOR, PATCH, 0, 0, 0, 0)
{
    PARAMETER_INITIALIZE(SymbolTableID);
    PARAMETER_INITIALIZE(module_version);
    PARAMETER_INITIALIZE(PDInfo);
    PARAMETER_INITIALIZE(PDSensorNativePatternInfoCount);
    PARAMETER_INITIALIZE(PDSensorNativePatternInfoID);
    PARAMETER_INITIALIZE(PDSensorNativePatternInfo);
    PARAMETER_INITIALIZE(PDBufferBlockPatternInfoCount);
    PARAMETER_INITIALIZE(PDBufferBlockPatternInfoID);
    PARAMETER_INITIALIZE(PDBufferBlockPatternInfo);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Constructor
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
PDAFConfigurationDataClass::PDAFConfigurationDataClass(
    const CHAR* name,
    UINT32 modeId,
    UINT16 mode,
    UINT16 subMode,
    UINT32 group)
    : ParameterModule(name, MAJOR, MINOR, PATCH, modeId, mode, subMode, group)
{
    PARAMETER_INITIALIZE(SymbolTableID);
    PARAMETER_INITIALIZE(module_version);
    PARAMETER_INITIALIZE(PDInfo);
    PARAMETER_INITIALIZE(PDSensorNativePatternInfo);
    PARAMETER_INITIALIZE(PDBufferBlockPatternInfo);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Destructor
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
PDAFConfigurationDataClass::~PDAFConfigurationDataClass()
{
    UnloadPDAFConfigurationData(this);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// GetName
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const CHAR* PDAFConfigurationDataClass::GetName(
    const CHAR* type)
{
    const CHAR* name = type;
    CHAR temp[ParameterFileSymbolTableEntry::TYPE_LEN + 1];
    if (PARAMETER_STRCMP(type, ParameterFileSymbolTableEntry::GetType(temp, "PDConfigData")) == 0)
    {
        name = "PDConfigData";
    }
    return name;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Load PDAFInformation
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL PDAFConfigurationDataClass::LoadPDAFInformation(
    ParameterFileSymbolTableEntry* entry,
    PDAFInformation* structure)
{
    BOOL result = TRUE;

    // Reading structure->PDAFName from the symbol table
    {
        UINT32 PDAFNameCount = 0;
        result = result && entry->ReadUInt32(&PDAFNameCount);
        ParameterFileSymbolTableEntry* pointerEntry1 = entry->Table->ReadPointerEntry(entry);
        result = result && pointerEntry1 != NULL;
        structure->PDAFName = NULL;
        if (result)
        {
            pointerEntry1->ReadString(&structure->PDAFName, PDAFNameCount);
        }
    }

    // Reading structure->PDAFLibraryName from the symbol table
    {
        result = result && entry->ReadUInt32(&structure->PDAFLibraryNameExists);
        structure->PDAFLibraryNameID = entry->ID;
        ParameterFileSymbolTableEntry* pointerEntry1 = entry->Table->ReadPointerEntry(entry);
        result = result && pointerEntry1 != NULL;
        if (result && structure->PDAFLibraryNameExists)
        {

            // Reading structure->PDAFLibraryName from the symbol table
            {
                result = result && pointerEntry1->ReadUInt32(&structure->PDAFLibraryNameExists);
                structure->PDAFLibraryNameID = entry->ID;
                ParameterFileSymbolTableEntry* pointerEntry3 = pointerEntry1->Table->ReadPointerEntry(pointerEntry1);
                result = result && pointerEntry3 != NULL;
                structure->PDAFLibraryName = NULL;
                if (result)
                {
                    pointerEntry3->ReadString(&structure->PDAFLibraryName, structure->PDAFLibraryNameExists);
                }
            }
        }
        else
        {
            PARAMETER_INITIALIZE(structure->PDAFLibraryName);
        }
    }
    result = result && entry->ReadUInt32(&structure->PDStatsDataType);
    structure->PDOrientation = (PDAFOrientation)entry->ReadEnum(&result);
    result = result && entry->ReadUInt32(&structure->PDBlackLevel);
    result = result && entry->ReadInt32(&structure->PDDefocusConfidenceThreshold);
    result = result && entry->ReadUInt32(&structure->PDDefocusBitShift);
    structure->PDSensorPDStatsFormat = (SensorPDStatsFormat)entry->ReadEnum(&result);
    result = result && entry->ReadFloat(&structure->PDOffsetCorrection);
    structure->PDPixelOrderType = (PDAFPixelOrderType)entry->ReadEnum(&result);
    structure->PDType = (PDAFType)entry->ReadEnum(&result);

    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Load PDAFPixelCoordinates
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL PDAFConfigurationDataClass::LoadPDAFPixelCoordinates(
    ParameterFileSymbolTableEntry* entry,
    PDAFPixelCoordinates* structure)
{
    BOOL result = TRUE;
    result = result && entry->ReadUInt32(&structure->PDXCoordinate);
    result = result && entry->ReadUInt32(&structure->PDYCoordinate);
    structure->PDPixelShieldInformation = (PDAFPixelShieldInformation)entry->ReadEnum(&result);

    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Load PDAFBlockPattern
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL PDAFConfigurationDataClass::LoadPDAFBlockPattern(
    ParameterFileSymbolTableEntry* entry,
    PDAFBlockPattern* structure)
{
    BOOL result = TRUE;
    result = result && entry->ReadUInt32(&structure->PDPixelCount);

    // Reading structure->PDPixelCoordinates from the symbol table
    {
        result = result && entry->ReadUInt32(&structure->PDPixelCoordinatesCount);
        structure->PDPixelCoordinatesID = entry->ID;
        ParameterFileSymbolTableEntry* pointerEntry1 = entry->Table->ReadPointerEntry(entry);
        result = result && pointerEntry1 != NULL;
        if (result)
        {
            structure->PDPixelCoordinates   = PARAMETER_NEW PDAFPixelCoordinates[structure->PDPixelCoordinatesCount];
        }
        if (!result || structure->PDPixelCoordinates == NULL)
        {
            structure->PDPixelCoordinatesCount = 0;
        }
        for (UINT32 i = 0; result && i < structure->PDPixelCoordinatesCount; i++)
        {
            result = result && LoadPDAFPixelCoordinates(pointerEntry1, &structure->PDPixelCoordinates[i]);
        }
    }
    result = result && camxsensorcommonClass::LoadDimension(entry, &structure->PDBlockDimensions);
    result = result && entry->ReadUInt32(&structure->PDOffsetHorizontal);
    result = result && entry->ReadUInt32(&structure->PDOffsetVertical);

    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Load PDAFSensorNativePatternInformation
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL PDAFConfigurationDataClass::LoadPDAFSensorNativePatternInformation(
    ParameterFileSymbolTableEntry* entry,
    PDAFSensorNativePatternInformation* structure)
{
    BOOL result = TRUE;
    result = result && entry->ReadUInt32(&structure->PDBlockCountHorizontal);
    result = result && entry->ReadUInt32(&structure->PDBlockCountVertical);

    // Reading structure->PDBlockPattern from the symbol table
    {
        result = result && entry->ReadUInt32(&structure->PDBlockPatternExists);
        structure->PDBlockPatternID = entry->ID;
        ParameterFileSymbolTableEntry* pointerEntry1 = entry->Table->ReadPointerEntry(entry);
        result = result && pointerEntry1 != NULL;
        if (result && structure->PDBlockPatternExists)
        {
            result = result && LoadPDAFBlockPattern(pointerEntry1, &structure->PDBlockPattern);
        }
        else
        {
            PARAMETER_INITIALIZE(structure->PDBlockPattern);
        }
    }
    result = result && camxsensorcommonClass::LoadFrameDimension(entry, &structure->PDCropRegion);
    result = result && entry->ReadFloat(&structure->PDDownscaleFactorHorizontal);
    result = result && entry->ReadFloat(&structure->PDDownscaleFactorVertical);

    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Load PDAFBlockPatternInformation
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL PDAFConfigurationDataClass::LoadPDAFBlockPatternInformation(
    ParameterFileSymbolTableEntry* entry,
    PDAFBlockPatternInformation* structure)
{
    BOOL result = TRUE;
    result = result && entry->ReadUInt32(&structure->PDStride);
    structure->PDBufferFormat = (PDAFBufferDataFormat)entry->ReadEnum(&result);

    // Reading structure->PDBlockPattern from the symbol table
    {
        result = result && entry->ReadUInt32(&structure->PDBlockPatternExists);
        structure->PDBlockPatternID = entry->ID;
        ParameterFileSymbolTableEntry* pointerEntry1 = entry->Table->ReadPointerEntry(entry);
        result = result && pointerEntry1 != NULL;
        if (result && structure->PDBlockPatternExists)
        {
            result = result && LoadPDAFBlockPattern(pointerEntry1, &structure->PDBlockPattern);
        }
        else
        {
            PARAMETER_INITIALIZE(structure->PDBlockPattern);
        }
    }

    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Load PDAFConfigurationData
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL PDAFConfigurationDataClass::LoadPDAFConfigurationData(
    ParameterFileSymbolTableEntry* entry,
    PDAFConfigurationData* structure)
{
    BOOL result = TRUE;
    result = result && Loadmodule_versionStruct(entry, &structure->module_version);
    result = result && LoadPDAFInformation(entry, &structure->PDInfo);

    // Reading structure->PDSensorNativePatternInfo from the symbol table
    {
        result = result && entry->ReadUInt32(&structure->PDSensorNativePatternInfoCount);
        structure->PDSensorNativePatternInfoID = entry->ID;
        ParameterFileSymbolTableEntry* pointerEntry1 = entry->Table->ReadPointerEntry(entry);
        result = result && pointerEntry1 != NULL;
        if (result)
        {
            structure->PDSensorNativePatternInfo   = PARAMETER_NEW PDAFSensorNativePatternInformation[structure->PDSensorNativePatternInfoCount];
        }
        if (!result || structure->PDSensorNativePatternInfo == NULL)
        {
            structure->PDSensorNativePatternInfoCount = 0;
        }
        for (UINT32 i = 0; result && i < structure->PDSensorNativePatternInfoCount; i++)
        {
            result = result && LoadPDAFSensorNativePatternInformation(pointerEntry1, &structure->PDSensorNativePatternInfo[i]);
        }
    }

    // Reading structure->PDBufferBlockPatternInfo from the symbol table
    {
        result = result && entry->ReadUInt32(&structure->PDBufferBlockPatternInfoCount);
        structure->PDBufferBlockPatternInfoID = entry->ID;
        ParameterFileSymbolTableEntry* pointerEntry1 = entry->Table->ReadPointerEntry(entry);
        result = result && pointerEntry1 != NULL;
        if (result)
        {
            structure->PDBufferBlockPatternInfo   = PARAMETER_NEW PDAFBlockPatternInformation[structure->PDBufferBlockPatternInfoCount];
        }
        if (!result || structure->PDBufferBlockPatternInfo == NULL)
        {
            structure->PDBufferBlockPatternInfoCount = 0;
        }
        for (UINT32 i = 0; result && i < structure->PDBufferBlockPatternInfoCount; i++)
        {
            result = result && LoadPDAFBlockPatternInformation(pointerEntry1, &structure->PDBufferBlockPatternInfo[i]);
        }
    }

    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Load module_versionStruct
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL PDAFConfigurationDataClass::Loadmodule_versionStruct(
    ParameterFileSymbolTableEntry* entry,
    PDAFConfigurationData::module_versionStruct* structure)
{
    BOOL result = TRUE;
    result = result && entry->ReadInt32(&structure->major_revision);
    result = result && entry->ReadInt32(&structure->minor_revision);
    result = result && entry->ReadInt32(&structure->incr_revision);

    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Unload PDAFInformation
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void PDAFConfigurationDataClass::UnloadPDAFInformation(
    PDAFInformation* structure)
{
    PARAMETER_DELETE[] structure->PDAFName;
    PARAMETER_DELETE[] structure->PDAFLibraryName;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Unload PDAFBlockPattern
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void PDAFConfigurationDataClass::UnloadPDAFBlockPattern(
    PDAFBlockPattern* structure)
{
    PARAMETER_DELETE[] structure->PDPixelCoordinates;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Unload PDAFSensorNativePatternInformation
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void PDAFConfigurationDataClass::UnloadPDAFSensorNativePatternInformation(
    PDAFSensorNativePatternInformation* structure)
{
    UnloadPDAFBlockPattern(&structure->PDBlockPattern);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Unload PDAFBlockPatternInformation
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void PDAFConfigurationDataClass::UnloadPDAFBlockPatternInformation(
    PDAFBlockPatternInformation* structure)
{
    UnloadPDAFBlockPattern(&structure->PDBlockPattern);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Unload PDAFConfigurationData
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void PDAFConfigurationDataClass::UnloadPDAFConfigurationData(
    PDAFConfigurationData* structure)
{
    UnloadPDAFInformation(&structure->PDInfo);
    for (UINT32 i = 0; i < structure->PDSensorNativePatternInfoCount; i++)
    {
        UnloadPDAFSensorNativePatternInformation(&structure->PDSensorNativePatternInfo[i]);
    }
    PARAMETER_DELETE[] structure->PDSensorNativePatternInfo;
    for (UINT32 i = 0; i < structure->PDBufferBlockPatternInfoCount; i++)
    {
        UnloadPDAFBlockPatternInformation(&structure->PDBufferBlockPatternInfo[i]);
    }
    PARAMETER_DELETE[] structure->PDBufferBlockPatternInfo;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Parse symbol table entry, and return a new object
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ParameterModule* PDAFConfigurationDataClass::Parse(
    ParameterSetManager* manager,
    ParameterFileSymbolTableEntry* entry) const
{
    PDAFConfigurationDataClass* cls = NULL;

    if (PARAMETER_STRCMP(Type, entry->Type) == 0 && Major == entry->Major &&
        Minor == entry->Minor && Patch == entry->Patch)
    {
        cls = PARAMETER_NEW PDAFConfigurationDataClass(GetName(entry->Type), 
            entry->ModeId, entry->Mode, entry->SubMode, entry->Group);
        if (cls != NULL)
        {
            BOOL result = TRUE;

            cls->SymbolTableID = entry->ID;
            cls->ID            = entry->ID;

            result = result && LoadPDAFConfigurationData(entry, cls);

            if (!result)
            {
                PARAMETER_DELETE cls;
                cls = NULL;
            }
        }
    }
    return (ParameterModule*)cls;
}


CAMX_NAMESPACE_END
